package com.ccsc.auth.utils;

import com.ccsc.auth.entity.ShiroResource;
import com.ccsc.auth.entity.ShiroRole;
import com.ccsc.auth.entity.ShiroSystem;
import com.ccsc.auth.entity.ShiroUser;
import com.google.common.collect.Lists;
import java.util.List;

/**
 * Created by XingWen on 2017/3/3.
 */
public class SSOUtil {
    public static List<ShiroRole> getRolesByUser(ShiroUser shiroUser){
        return shiroUser.getRoles();
    }

    public static List<ShiroResource> getResourcesBySysKey(ShiroUser shiroUser, String SysKey){
        List<ShiroSystem> systemList = shiroUser.getSystems();
        List<ShiroResource> resourceList = Lists.newArrayList();
        if(systemList!=null && systemList.size()>0){
            for(ShiroSystem shiroSystem : systemList){
                if(SysKey.equals(shiroSystem.getSystemIdentifier()) && shiroSystem.getResources() != null && shiroSystem.getResources().size() > 0){
                    resourceList = shiroSystem.getResources();
                }
            }
        }

        return resourceList;
    }
}
